// Package handler
// @Author: zhangdi
// @File: func
// @Version: 1.0.0
// @Date: 2023/7/6 15:38
package handler

import (
	"ideatools/application/constant/enums"
	"ideatools/application/core/events"
	"ideatools/application/db/dbdto"
	"ideatools/application/db/dbservice"
	"ideatools/application/db/entity"
	"ideatools/application/pkgs/utils"
	"ideatools/pkg/chat"
)

func NotifyFrontMessageContent(ContentInfo *dbdto.ChatContentInfo, clipTexts []string) {

	toolInfo := dbservice.NewUserToolService().FindOneById(ContentInfo.ToolId)
	dtoToolInfo := &dbdto.UserToolInfo{}
	utils.DtoToEntity(toolInfo, dtoToolInfo)

	//触发事件
	events.OnContentAdd(&events.MessageContent{
		ClipboardTexts: &clipTexts,
		ContentInfo:    ContentInfo,
		ToolInfo:       dtoToolInfo,
	})

}

func GetDoalogChatContents(dialogId uint) []chat.CompletionMessage {
	SendContents := make([]chat.CompletionMessage, 0)

	//获取上下文
	res := dbservice.ChatDialog().GetListChatContent(dialogId, false)

	if res.Code == enums.RespCodeOk {
		list := res.Data.([]*entity.ChatContent)

		for i, content := range list {

			item := chat.CompletionMessage{
				Role:    content.Role,
				Content: content.Content,
				Name:    "",
			}
			SendContents = append(SendContents, item)
			i++
		}
	}

	return SendContents
}
